Name: Sarvesh Sridhar
Reg.No: 19BAI1057
Dataset used: Skin Cancer HAM10000
Link: https://www.kaggle.com/surajghuwalewala/ham1000-segmentation-and-classification
Experimentation of Edge Detection Techniques
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage import io
from skimage.util import random_noise
plt.rcParams["figure.figsize"] = [8, 8]
plt.rcParams["figure.autolayout"] = True
gray_img = cv2.imread('D:/Datasets/HAM1000/images/ISIC_0024313.jpg',0)
img = cv2.imread('D:/Datasets/HAM1000/images/ISIC_0024313.jpg',1)
plt.subplot(1,2,1)
io.imshow(gray_img)
plt.subplot(1,2,2)
io.imshow(img)
<matplotlib.image.AxesImage at 0x26196bd1c10>
sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize = 5)
sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize = 5)
sobelxy = cv2.Sobel(img, cv2.CV_64F, 1, 1, ksize = 5)
plt.subplot(1,2,1)
io.imshow(sobelx)
plt.title("Sobel x")
plt.subplot(1,2,2)
io.imshow(sobely)
plt.title("Sobel y")
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Text(0.5, 1.0, 'Sobel y')
io.imshow(sobelxy)
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
<matplotlib.image.AxesImage at 0x26197f61700>
sobelx = cv2.Sobel(gray_img, cv2.CV_64F, 1, 0, ksize = 5)
sobely = cv2.Sobel(gray_img, cv2.CV_64F, 0, 1, ksize = 5)
sobelxy = cv2.Sobel(gray_img, cv2.CV_64F, 1, 1, ksize = 5)
plt.subplot(1,2,1)
io.imshow(sobelx)
plt.title("Sobel x")
plt.subplot(1,2,2)
io.imshow(sobely)
plt.title("Sobel y")
Text(0.5, 1.0, 'Sobel y')
io.imshow(sobelxy)
<matplotlib.image.AxesImage at 0x261977dc670>
canny = cv2.Canny(img,75,100)
io.imshow(canny)
<matplotlib.image.AxesImage at 0x26197a73af0>
canny = cv2.Canny(gray_img,75,100)
io.imshow(canny)
<matplotlib.image.AxesImage at 0x26197aea2b0>
#prewitt
kernelx = np.array([[1,1,1],[0,0,0],[-1,-1,-1]])
kernely = np.array([[-1,0,1],[-1,0,1],[-1,0,1]])
img_prewittx = cv2.filter2D(img, -1, kernelx)
img_prewitty = cv2.filter2D(img, -1, kernely)
plt.subplot(1,2,1)
io.imshow(img_prewittx)
plt.title("Prewitt X")
plt.subplot(1,2,2)
io.imshow(img_prewitty)
plt.title("Prewitt Y")
Text(0.5, 1.0, 'Prewitt Y')
io.imshow(img_prewittx+img_prewitty)
<matplotlib.image.AxesImage at 0x26197bf8cd0>
#prewitt
kernelx = np.array([[1,1,1],[0,0,0],[-1,-1,-1]])
kernely = np.array([[-1,0,1],[-1,0,1],[-1,0,1]])
img_prewittx = cv2.filter2D(gray_img, -1, kernelx)
img_prewitty = cv2.filter2D(gray_img, -1, kernely)
plt.subplot(1,2,1)
io.imshow(img_prewittx)
plt.title("Prewitt X")
plt.subplot(1,2,2)
io.imshow(img_prewitty)
plt.title("Prewitt Y")
Text(0.5, 1.0, 'Prewitt Y')
io.imshow(img_prewittx+img_prewitty)
<matplotlib.image.AxesImage at 0x26197dc5f10>
laplacian = cv2.Laplacian(img,cv2.CV_64F)
io.imshow(laplacian)
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
<matplotlib.image.AxesImage at 0x261980596d0>
laplacian = cv2.Laplacian(gray_img,cv2.CV_64F)
io.imshow(laplacian)
<matplotlib.image.AxesImage at 0x26197eac700>
img = random_noise(gray_img, mode='gaussian')
io.imshow(img)
plt.title("Poisson Noise")
Text(0.5, 1.0, 'Poisson Noise')
sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize = 5)
sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize = 5)
sobelxy = cv2.Sobel(img, cv2.CV_64F, 1, 1, ksize = 5)
plt.subplot(1,2,1)
io.imshow(sobelx)
plt.title("Sobel x")
plt.subplot(1,2,2)
io.imshow(sobely)
plt.title("Sobel y")
Text(0.5, 1.0, 'Sobel y')
io.imshow(sobelxy)
<matplotlib.image.AxesImage at 0x261990d9040>
import numpy as np
img_copy = (img*255).astype(np.uint8)
canny = cv2.Canny(img_copy,1,100)
io.imshow(canny)
<matplotlib.image.AxesImage at 0x26196ffcc10>
#prewitt
kernelx = np.array([[1,1,1],[0,0,0],[-1,-1,-1]])
kernely = np.array([[-1,0,1],[-1,0,1],[-1,0,1]])
img_prewittx = cv2.filter2D(img, -1, kernelx)
img_prewitty = cv2.filter2D(img, -1, kernely)
plt.subplot(1,2,1)
io.imshow(img_prewittx)
plt.title("Prewitt X")
plt.subplot(1,2,2)
io.imshow(img_prewitty)
plt.title("Prewitt Y")
Text(0.5, 1.0, 'Prewitt Y')
io.imshow(img_prewittx+img_prewitty)
<matplotlib.image.AxesImage at 0x2619c293dc0>
laplacian = cv2.Laplacian(img,cv2.CV_64F)
io.imshow(laplacian)
<matplotlib.image.AxesImage at 0x261983876d0>
Sobel Edge Detection technique detects edges better for color image than grayscale image.
Canny Edge Detection technique detects edges better for colour image than grayscale image (comparing results with naked eye)
Prewitt Edge Detection technique gives good result with both color and grayscale image but comparing it with naked eye, canny can be said to perform better. It gives off a glossy shade/elevation over the edges and its interior in our image.
Laplacian Edge Detection gave pixel like output for color image and very light output for grayscale image.
We have tried experimenting it with Gaussian Noised image. It is observed that sobel x-axis and y-axis kernel perform slightly better than the rest of the techniques as we can see a very light edges in the output.
So for Grayscaled imgae, sobel (x-axis, y-axis kernels), canny, Prewitt performs better. For color image, sobel (x-axis, y-axis kernels), canny, Prewitt performs better. For noisy image, sobel (x-axis,y-axis kernels) produces some output as compared to rest.